001    /*
002     * Copyright 2004-2005 Stephen J. McConnell.
003     *
004     * Licensed  under the  Apache License,  Version 2.0  (the "License");
005     * you may not use  this file  except in  compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *   http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed  under the  License is distributed on an "AS IS" BASIS,
012     * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
013     * implied.
014     *
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    
019    package net.dpml.transit.tools;
020    
021    import java.util.ArrayList;
022    import java.util.List;
023    
024    import org.apache.tools.ant.BuildException;
025    import org.apache.tools.ant.ComponentHelper;
026    import org.apache.tools.ant.Project;
027    
028    /**
029     * Task that initializes the Transit sub-system during which a transit
030     * is assigned to the current project.  In addition the initization procedures
031     * establishes a set of ant properties enabling convenient script based access
032     * to DPML dirctories.
033     *
034     * <pre>
035      <project name="example"
036          xmlns:transit="antlib:net.dpml.transit">
037        <transit:init/>
038        <echo message="Home: ${dpml.home}"/>
039        <echo message="Cache: ${dpml.cache}"/>
040        <echo message="Templates: ${dpml.templates}"/>
041        <echo message="Docs: ${dpml.docs}"/>
042        <echo message="Docs: ${dpml.dist}"/>
043      </project></pre>
044     * <p>Output from the above example is shown below:</p>
045     * <pre>
046         [echo] Home: C:\system\dpml
047         [echo] Cache: C:\system\dpml\main
048         [echo] Templates: C:\system\dpml\templates
049         [echo] Docs: C:\system\dpml\docs
050         [echo] Docs: C:\system\dpml\dist
051     * </pre>
052     *
053     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
054     * @version 1.0.1
055     */
056    public class MainTask extends TransitTask
057    {
058        // ------------------------------------------------------------------------
059        // state
060        // ------------------------------------------------------------------------
061    
062       /**
063        * List of plugin declarations.
064        */
065        private List m_mappings = new ArrayList();
066    
067        // ------------------------------------------------------------------------
068        // constructor
069        // ------------------------------------------------------------------------
070    
071       /**
072        * Creation of a new Main task.
073        */
074        public MainTask()
075        {
076            super();
077        }
078    
079        // ------------------------------------------------------------------------
080        // Task
081        // ------------------------------------------------------------------------
082    
083       /**
084        * Create and return a new plugin definition.
085        * @return the plugin definition
086        */
087        public MapDataType createMap()
088        {
089            MapDataType map = new MapDataType();
090            m_mappings.add( map );
091            return map;
092        }
093    
094       /**
095        * Set the project.
096        * @param project the current project
097        */
098        public void setProject( Project project )
099        {
100            setTaskName( "transit" );
101            super.setProject( project );
102        }
103    
104       /**
105        * Updates properties on the current project and install any plugins declared
106        * as children of the transit init tag.
107        *
108        * @exception BuildException if an execution error occurs
109        */
110        public void execute() throws BuildException
111        {
112            Project project = getProject();
113            TransitComponentHelper.initialize( project );
114            ComponentHelper ch = ComponentHelper.getComponentHelper( project );
115            MapDataType[] maps = (MapDataType[]) m_mappings.toArray( new MapDataType[0] );
116            TransitComponentHelper.register( maps );
117        }
118    }
119